package com.tianxiang.service;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;

import com.tianxiang.model.Node;
import com.tianxiang.utils.Tools;

public class ShowTreeService {
ArrayList<Node> nodes;

/**
 * 获取制定文件夹下的目录信息
 * @param path	指定的文件夹的绝对路径
 * @return	包含个节点的集合列表
 */
public ArrayList<Node> getNodes( String root,String path) {
	nodes=new ArrayList<Node>();
	
	File parentFile=new File(path);
	File childs[]=parentFile.listFiles();
	for (File file : childs) {
		if (file.isFile()) {
			continue;	//用于排除文件
		}
		Node node=new Node();
		node.setId(file.getAbsolutePath().substring(Tools.getAcessPath(root, "", "").length()));
		System.err.println("note id="+node.getId());
		node.setText(file.getName());
		nodes.add(node);
	}
	showNodesInfo(nodes);
	return nodes;
}

void showNodesInfo(ArrayList<Node> nodes){
	System.out.println("Id\ttext\tleaf");
	for (@SuppressWarnings("rawtypes")
	Iterator iterator = nodes.iterator(); iterator.hasNext();) {
		Node node = (Node) iterator.next();
		System.out.print(node.getId()+"\t");
		System.out.print(node.getText()+"\t");
		System.out.println(node.isLeaf());
		
	}
}

}
